There are a wide variety of commercially available microprocessors (often referred to as xe2x80x9cprocessorsxe2x80x9d) that a system designer may select for a particular application. Many of these processors are based on different design philosophies such as reduced instruction set computing (RISC) versus complex instruction set computing (CISC) and on different length of an instruction word (32-bit versus 64-bit versus 128-bit). In addition to different design philosophies manifested by the instruction set, various other architectural differences may be found in various processors. For example, some processors may execute instructions in parallel while others do not. Other processors may use shared memory while others do not. Although there are a number of commercially processors based on competing and often incompatible architecture, the well-known x86 architecture is currently a popular architecture for which a tremendous amount of computer software has been developed. However, because of the necessity to maintain backward compatibility with less powerful processors, the x86 suffers from a lack of performance when compared to processors based on different architectures not constrained by the need to run legacy software and maintain backward compatibility.
When legacy (or base) software is designed, it is typically written for a particular processor and computer system based on a particular architecture. And while it is possible to port foreign software to a new, but more advanced, architecture, it is a difficult task that requires a complete understanding of both the legacy architecture and the new architecture. Further, there are times where the source code, the human readable version of the foreign software, is not available. In such instances, it is often very difficult to accurately recreate the original functions of the software on the new architecture. This difficulty arises because of the various nuances the foreign software often incorporates to take advantage of the features of the legacy architecture.
Clearly, it is useful to automate the translation of foreign software originally developed for a legacy architecture to a computer system, or processing xe2x80x9cplatform,xe2x80x9d having an architecture that is different from that for which the software was originally designed. Translation allows foreign software to execute on computer systems other than the one it was originally written and therefore increases the commercial value of the software. Further, translation can extend the life of the software past the life of the computer system for which it was originally designed. Clearly, it would be desirable if the translation process were automated to reduce, or eliminate, the cost to port foreign software to another architecture.
The process of translating software from a foreign architecture to a native architecture is often referred to in the art as binary translation and various binary translation techniques are well known in the art. In general, binary translation converts binary foreign code, that is legacy software originally written and compiled for a specific architecture, to host code capable of being executed by a processor and computer system that is based on a different architecture. More specifically, binary compilation is the process of detecting each instruction and converting these instructions to one or more equivalent native operations. While it is often impossible to achieve a one-to-one translation of each instruction due to architectural differences, the translation process is especially difficult where the data constructs and memory addressing schemes differ between the foreign and native or target architectural platforms and where the source code is not available. Accordingly, it is often necessary to analyze binary foreign code (rather than source code) to determine the most efficient equivalent instruction or instructions for achieving the same result when executed on the new architecture. This analysis and translation process is typically slow and labor intensive. Accordingly, any reduction of the need for the analysis and compilation not only has an important bearing on binary code performance but also on the cost to port the code to the native platform.
By its very nature, software tends to be complex and must execute with a virtually a zero tolerance for errors. Unfortunately, certain areas of software translation are extremely difficult. Typically, these involve specialized instructions that deal with hardware components, high-performance instructions, addressing modes, input/output and other aspects that are closely tied to the hardware developed for the legacy architecture.
In some prior art binary compilation schemes, the target platform typically includes a foreign engine adapted to execute foreign code instructions and a native engine designed to execute translated binary code (host code). This type of scheme translates certain foreign instructions during the compile process into a corresponding set of native binary code while other foreign instructions are typically not translatable. Where it is not possible to readily translate foreign code into host code, the target platform must be able to switch between the foreign engine and the native engine during run-time execution. Since, translated binary code needs to run as fast or faster on the target platform than the foreign code did on the foreign platform, it is often unacceptable to constantly switch between the two engines during run-time. For this reason, it is desirable to more fully translate the binary foreign code to host code prior to run-time.
Thus, it is desirable to provide a method that achieves efficient and accurate translation of software so that it can be executed to operate on a variety of computer platforms without the need of expensive manual translation. Further, it is desirable to provide a method that achieves efficient and accurate translation of software so that it can be executed on a variety of computer platforms without have to switch between a foreign engine and a native engine.
The present invention relates to a method for efficiently executing translated binary code on a computer platform. More specifically, the present invention relates to a method that reduces the time for analysis and compilation of foreign code to host code. The method uses low-level code correspondence checking during binary runtime translation process. Advantageously, the method does not require obvious translation of foreign code into host code.
The present invention improves the efficiency of the binary translation process by correlating previously translated binary host code to foreign code. This approach eliminates the repetitive process of translating the same foreign code more than once. In this approach, the translation process builds a database of translated foreign code that a software layer checks for correspondence whenever the foreign code is subsequently accessed. The database of binary code is preferably stored on a hard disk.
In one preferred embodiment, as each sequence of foreign code (that is an instruction or a group of instructions) is acquired from secondary storage, correspondence is determined between the foreign code and the cache of host code. If corresponding host code is included in the database, it is transferred to system memory for execution. If the host code in the database does not include corresponding translated binary code then a translation process, which uses various compilation techniques, is invoked to translate the foreign code to host code. Newly compiled code is then added to the database so that it may be subsequently accessed should the need arise. Thus, the present invention eliminates the slow and repetitive process of translating the same foreign code more than once. In this manner, the host system may execute translated binary code in the native environment and achieve comparable or better performance than the foreign code executing on the foreign system.
To further improve efficiency, the present invention also maintains the database so performance is not decreased. Thus, if a portion of the code in the database is not frequently accessed, it can be removed from the database or moved to an archival database. Further, if a portion of the code has not been accessed within a selected period of time, it can be removed from the database. If the removed portion of code is subsequently required, it will then simply be re-translated.
As will be appreciated by one skilled in the art, most operating system and application programs are initially stored in a secondary storage device such as a disk drive. When a user selects the program for execution, the program""s code is transferred from the disk drive to faster system-level memory. For larger application programs or operating systems, only a portion of the code may be transferred to memory as required by the particular task to be performed. Indeed, it is common for repeated disk accesses to transfer code from disk to system memory as the program performs a plurality of tasks. Each time the program swaps code out of a portion of memory and replaces it with new code, the host computer system must make sure that the proper host code is executed. During these transfer operations, the present invention solves the problem of how to rapidly translate foreign code into host code without degrading program performance.